﻿<UserControl x:Class="Chapters.Chapter08.OverlayRectsOn3DObjects"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
	<UserControl.Resources>
		<Border x:Key="BrushVisual"
				BorderBrush="Black"
				BorderThickness="10"
				Background="LightBlue"
				Width="400"
				Height="300" />

		<ModelUIElement3D x:Key="Plane"
						  x:Shared="False">
			<ModelUIElement3D.Model>
				<GeometryModel3D>
					<GeometryModel3D.Geometry>
						<MeshGeometry3D Positions="-0.625,0.5,0 0.625,0.5,0 0.625,-0.5,0 -0.625,-0.5,0."
										Normals="0,0,1 0,0,1 0,0,1 0,0,1"
										TriangleIndices="0,3,2 0,2,1"
										TextureCoordinates="0,0 1,0 1,1 0,1" />
					</GeometryModel3D.Geometry>

					<GeometryModel3D.Material>
						<DiffuseMaterial>
							<DiffuseMaterial.Brush>
								<VisualBrush Visual="{StaticResource BrushVisual}" />
							</DiffuseMaterial.Brush>
						</DiffuseMaterial>
					</GeometryModel3D.Material>

				</GeometryModel3D>
			</ModelUIElement3D.Model>

			<ModelUIElement3D.Transform>
				<Transform3DGroup>
					<RotateTransform3D>
						<RotateTransform3D.Rotation>
							<AxisAngleRotation3D Axis="0,1,0"
												 Angle="45" />
						</RotateTransform3D.Rotation>
					</RotateTransform3D>
					<TranslateTransform3D />
				</Transform3DGroup>
			</ModelUIElement3D.Transform>

		</ModelUIElement3D>

		<Style TargetType="Rectangle">
			<Setter Property="Stroke"
					Value="Red" />
			<Setter Property="StrokeThickness"
					Value="2" />
		</Style>
	</UserControl.Resources>
	<DockPanel>
		<CheckBox DockPanel.Dock="Bottom"
				  Content="Show 2D Rect Overlay"
				  Click="ShowOverlay" />
		<Grid>
			<Viewport3D x:Name="_viewport">
				<Viewport3D.Camera>
					<PerspectiveCamera FieldOfView="60"
									   Position="0,2,10"
									   LookDirection="0,-2,-10"
									   UpDirection="0,1,0" />
				</Viewport3D.Camera>

				<!-- This will hold the Plane models -->
				<ContainerUIElement3D x:Name="_container" />

				<ModelVisual3D>
					<ModelVisual3D.Content>
						<AmbientLight Color="White" />
					</ModelVisual3D.Content>
				</ModelVisual3D>

			</Viewport3D>

			<Canvas x:Name="_rectOverlay" />
		</Grid>
	</DockPanel>
</UserControl>
